package yxy.cherry.battle.module.affix.buff;

import yxy.cherry.battle.Battle;
import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.module.PropertyData;
import yxy.cherry.battle.module.PropertyType;
import yxy.cherry.battle.module.affix.AffixFactory.BuffTypeEnum;
import yxy.cherry.battle.module.affix.Buff;
import yxy.cherry.battle.module.affix.BuffType;
import yxy.cherry.battle.module.record.stream.RecordStream39ChangeAttribute;
import yxy.cherry.battle.module.record.stream.RecordStream_SKL;
import yxy.cherry.data.bean.skill;

/**
 * 按比例增加属性（以目标的属性值乘以增加比例，为附加了buff的角色增加属性）
 *
 * */
@BuffType(Type = BuffTypeEnum.属性加)
public class Affix_64_属性加 extends Buff {

	private PropertyType get属性类型1() {
		return PropertyType.forNumber(getParam(0));
	}

	private int get属性增加1() {
		return getParam(1);
	}

	private PropertyType get属性类型2() {
		return PropertyType.forNumber(getParam(2));
	}

	private int get属性增加2() {
		return getParam(3);
	}

	public Affix_64_属性加(Fighter source, Fighter target, skill skilldata, int[] params) {
		super(source, target, skilldata, params);
	}

	@Override
	public boolean exec(Fighter source, Fighter target) {
		PropertyType 属性类型1 = get属性类型1();
		PropertyType 属性类型2 = get属性类型2();
		int attribute1 = 0;
		int attribute2 = 0;
		if (属性类型1 != null) {
			attribute1 = 属性类型1.getNumber();
		}
		if (属性类型2 != null) {
			attribute2 = 属性类型2.getNumber();
		}

		PropertyData propertyData = new PropertyData();
		boolean set = false;
		//纵向叠加参数
		int overlay = 1;
		if (getOverlayMax() > 0) {
			overlay = getOverlay();
		}

		long 增加值1 = 0;
		long 增加值2 = 0;
		if (属性类型1 != null && get属性增加1() > 0) {
			增加值1 = target.getData().getPropertyData().getValue(属性类型1) * overlay * get属性增加1() / VALUE_比率分母;
			propertyData.setValue(属性类型1, 增加值1);
			set = true;
		}
		if (属性类型2 != null && get属性增加2() > 0) {
			增加值2 = target.getData().getPropertyData().getValue(属性类型2) * overlay * get属性增加2() / VALUE_比率分母;
			propertyData.setValue(属性类型2, 增加值2);
			set = true;
		}
		if (set) {
			setPropertyData(propertyData);
		}

		getRecord().stream(new RecordStream_SKL(source,this.getSkilldata().getId())).record();
		getRecord().stream(new RecordStream39ChangeAttribute(target, this, attribute1, 增加值1, attribute2, 增加值2)).record();
		Battle.battleLogger(6,"属性加：目标"+source.getName()+"属性1:"+attribute1+"增加值："+增加值1+"属性2："+attribute2+"增加值："+增加值2);

		return true;
	}

	@Override
	public BuffType getBuffType() {
		return BuffType.属性加效果;
	}

	@Override
	public BuffStateType getBuffStateType() {
		return BuffStateType.属性加状态;
	}
}